<div class="container">
  
        <h1 id="pkg-overview">package httptrace</h1>

        <p><code>import "net/http/httptrace"</code>

        </p><p>
Package httptrace provides mechanisms to trace the events within
HTTP client requests.</p>


        
  
    <div class="panel-group">
    
      <div class="panel panel-default" id="example-package">
        <div class="panel-heading"><a class="accordion-toggle" data-toggle="collapse" href="#ex-package">Example</a></div>
        <div class="panel-collapse collapse" id="ex-package"><div class="panel-body">
          
          <p>Code:<span class="pull-right"><a href="?play=package">play</a> </span>
          </p><pre>req, _ := http.NewRequest("GET", "http://example.com", nil)
trace := &amp;httptrace.ClientTrace{
    GotConn: func(connInfo httptrace.GotConnInfo) {
        fmt.Printf("Got Conn: %+v\n", connInfo)
    },
    DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
        fmt.Printf("DNS Info: %+v\n", dnsInfo)
    },
}
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
_, err := http.DefaultTransport.RoundTrip(req)
if err != nil {
    log.Fatal(err)
}
</pre>
          
        </div></div>
      </div>
    
    </div>
  


        
        

        

        

        
        
          
          
        

        
        


<p><a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go">trace.go</a> </p>

        
        

        
        

        
        
        
          <h2 data-kind="f" id="WithClientTrace">func <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L33" title="View Source">WithClientTrace</a>  </h2>
          <p>
WithClientTrace returns a new context based on the provided parent
ctx. HTTP client requests made with the returned context will use
the provided trace hooks, in addition to any previous hooks
registered with ctx. Any hooks defined in the provided trace will
be called first.
</p>

          
  

        

        
        

        
          <h2 data-kind="t" id="ClientTrace">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L79" title="View Source">ClientTrace</a>  </h2>
          <p>
ClientTrace is a set of hooks to run at various stages of an outgoing
HTTP request. Any particular hook may be nil. Functions may be
called concurrently from different goroutines and some may be called
after the request has completed or failed.
</p>
<p>
ClientTrace currently traces a single HTTP request &amp; response
during a single round trip and has no hooks that span a series
of redirected requests.
</p>
<p>
See <a href="https://blog.golang.org/http-tracing">https://blog.golang.org/http-tracing</a> for more.
</p>

          
          
          
  


          
            <h3 data-kind="f" id="ContextClientTrace">func <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L23" title="View Source">ContextClientTrace</a>  </h3>
            <p>
ContextClientTrace returns the ClientTrace associated with the
provided context. If none, it returns nil.
</p>

            
  

          

          
        
          <h2 data-kind="t" id="DNSDoneInfo">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L204" title="View Source">DNSDoneInfo</a>  </h2>
          <p>
DNSDoneInfo contains information about the results of a DNS lookup.
</p>

          
          
          
  


          

          
        
          <h2 data-kind="t" id="DNSStartInfo">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L199" title="View Source">DNSStartInfo</a>  </h2>
          <p>
DNSStartInfo contains information about a DNS request.
</p>

          
          
          
  


          

          
        
          <h2 data-kind="t" id="GotConnInfo">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L226" title="View Source">GotConnInfo</a>  </h2>
          <p>
GotConnInfo is the argument to the ClientTrace.GotConn function and
contains information about the obtained connection.
</p>

          
          
          
  


          

          
        
          <h2 data-kind="t" id="WroteRequestInfo">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L156" title="View Source">WroteRequestInfo</a>  </h2>
          <p>
WroteRequestInfo contains information provided to the WroteRequest
hook.
</p>

<div class="clearfix" id="x-footer">
  <div class="container">
    <a href="http://studygolang.com/" target="_blank">Go语言中文网</a>
    <span class="text-muted">|</span> <a href="http://golang.org/" target="_blank">Go Language</a>
    <span class="pull-right"><a href="#">Back to top</a></span>
  </div>
</div>
<script src="../assets/jquery-2.0.3.min.js"></script>
<script src="../assets/bootstrap.min.js"></script>
<script src="../assets/site.js"></script>


</div>